// TOWN SCRIPT
//    Town 4: Dragonite Caves

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documenation. States you write
// yourself should be numbered from 10-100.

begintownscript;

variables;

int i,j,k,lvl,choice,choice2;

body;

beginstate INIT_STATE;
// This state called whenever this town is entered.
	if (get_flag(9,4) == 0) {
		reset_dialog_preset_options(0);
		add_dialog_str(0,"The caves down here are slightly more noisy than the previous ones. Not only that, but the voices seem to be actual communication, rather than just the hissing of the dumb lizards.",0);
		add_dialog_str(1,"It's a good bet that this is where the dragonites live.",0);
		choice = run_dialog(0);
		if (choice == 1)
			set_flag(9,4,1);
	}

	if ((get_flag(2,29) == 1) && (get_flag(200,5) == 0)) {
		erase_char(7);
		activate_hidden_group(1);
		set_name(40,"Monson");
	}

	if (get_flag(200,5) == 1) {
		erase_char(6);
		erase_char(7);
		erase_char(8);
		erase_char(9);
		erase_char(40);
	}

//Names
	set_name(6,"Duffy");
	set_char_dialogue_pic(6,1973,0);
	set_name(7,"Monson");
	set_name(8,"Dodd");
	set_name(9,"Copeland");

//Groups
	add_range_to_group(6,9,1);

	set_crime_tolerance(5);

break;

beginstate EXIT_STATE;
// Always called when the town is left.
break;

beginstate START_STATE;
break;

beginstate 10;
	if (get_flag(0,4) == 0) {
		reset_dialog_preset_options(0);
		add_dialog_str(0,"There's a secret passage here, leading to a narrow, winding corridor.",0);
		add_dialog_str(1,"There are hushed voices, whispering from the other end.",0);
		choice = run_dialog(0);
		if (choice == 1)
			set_flag(0,4,1);
	}
break;

beginstate 11;
	if (get_flag(1,4) == 0) {
		reset_dialog_preset_options(0);
		add_dialog_str(0,"You emerge from the passage and find yourself at the tip of a sword. A quick glance to the wall across from you also reveals a razor sharp arrow aimed directly at your throat.",0);
		add_dialog_str(1,"The bonfire at the other end of this small cave shows that the current denizens are not dragonites, but humans! When they realize that you're not dragonites either, they cautiously lower their weapons.",0);
		add_dialog_str(2,"One of the men standing near the fire beckons you forward, to speak with him, no doubt.",0);
		choice = run_dialog(0);
		if (choice == 1)
			set_flag(1,4,1);
	}
break;

beginstate 12;
	if (get_flag(2,4) == 0) {
		reset_dialog();
		add_dialog_str(0,"This seems to be some kind of shrine. The only notable feature in this room is a fresh, oblong skull resting on a basalt pedestal.",0);
		add_dialog_choice(0,"How morbid.");
		choice = run_dialog(0);
		if (choice == 1)
			set_flag(2,4,1);
	}
break;

beginstate 13;
	if (get_flag(3,4) == 0) {
		reset_dialog_preset_options(0);
		add_dialog_str(0,"It only takes a glance around this room to tell what it's used for. Various implements of torture sit neatly on a counter, and rotting bodies and bones are strewn about the cave.",0);
		add_dialog_str(1,"The most recent victim of harsh treatment is still chained to the wall.",0);
		choice = run_dialog(0);
		if (choice == 1)
			set_flag(3,4,1);
	}
break;

beginstate 14;
	reset_dialog();
	add_dialog_str(0,"A close examination of the most recent victim of the dragonites' torture indicates that he did not die quickly. There's little left now but bones, but it appears his skin was melted off, most likely while he was still alive.",0);
	add_dialog_str(1,"Even the bones themselves have deep cuts and abrasions. This man died very painfully.",0);
	add_dialog_str(2,"You touch the bone, and then immediately wish you hadn't. It has a soft, rubbery feel to it. It's disturbing, to say the least.",0);
	add_dialog_choice(0,"Eww...");
	choice = run_dialog(0);
	if (choice == 1)
		end();
break;

beginstate 15;
	if (get_flag(5,4) == 0) {
		reset_dialog_preset_options(0);
		add_dialog_str(0,"Ahead of you is a doorway guarded by two giant stone dragons. They're just statues. Hopefully they stay that way.",0);
		choice = run_dialog(0);
		if (choice == 1)
			set_flag(5,4,1);
	}
break;

beginstate 16;
	if (get_flag(6,4) == 0) {
		reset_dialog();
		add_dialog_str(0,"Fortunately, these statues remain statues, even as you walk between them.",0);
		add_dialog_str(1,"Ahead lies a vast cavern with a deep, wide pit in the center. Molten lava flows in falls from openings above, down into the pit. It's almost breathtaking. Almost.",0);
		add_dialog_str(2,"After a quick glance around, you can tell what this room is. It's a temple of sorts. In fact, you seem to have interrupted a ceremony of some kind. The dragonites here seem displeased at your presence. I wonder why?",0);
		add_dialog_choice(0,"Oops.");
		choice = run_dialog(0);
		if (choice == 1)
			set_flag(6,4,1);
	}
break;

beginstate 17;
	if (get_flag(7,4) == 0) {
		reset_dialog_preset_options(0);
		add_dialog_str(0,"This cave, while about the same size as the rest of the caves, appears to house only one dragonite.",0);
		if (get_flag(200,4) == 1)
			add_dialog_str(1,"This must be the home of the high shaman you killed.",0);
		else
			add_dialog_str(1,"This must be the home of someone very important.",0);
		choice = run_dialog(0);
		if (choice == 1)
			set_flag(7,4,1);
	}
break;

beginstate 18;
	if (get_flag(8,4) == 0) {
		reset_dialog_preset_options(0);
		add_dialog_str(0,"There's nothing in this room but a stairway leading down. Considering how well guarded it was, it could be the way into the dragon's lair.",0);
		choice = run_dialog(0);
		if (choice == 1)
			set_flag(8,4,1);
	}
break;

beginstate 19;
	if (character_in_party(401) > 0) {
		reset_dialog();
		add_dialog_str(0,"Monson glances up the stairs, then at you. _I'm not leaving without everyone else. If you're leaving now, I'm staying here._",0);
		add_dialog_choice(0,"Leave.");
		add_dialog_choice(1,"Stay.");
		choice = run_dialog(0);
		if (choice == 1) {
			reset_dialog_preset_options(0);
			add_dialog_str(0,"Monson starts heading back to the hidden cave. _I'll be where you found me if you need any help down here._",0);
			choice2 = run_dialog(0);
			if (choice2 == 1) {
				remove_char_from_party(401);
				move_to_new_town(3,39,14);
			}
		}
		if (choice == 2)
			block_entry(1);
	}
	else
		move_to_new_town(3,39,14);
break;

beginstate 20;
	move_to_new_town(5,12,41);
break;

beginstate 21;
	if (character_in_party(401) > 0) {
		add_dialog_str(0,"Monson turns to face you. _Do you want me to stay here?_",0);
		add_dialog_choice(0,"Yes, stay here.");
		add_dialog_choice(1,"No, stick around.");
		choice = run_dialog(0);
		if (choice == 1) {
			reset_dialog_preset_options(0);
			add_dialog_str(0,"Monson moves back to where you met him. _I'll be here if you need any more help._",0);
			choice2 = run_dialog(0);
			if (choice2 == 1)
				remove_char_from_party(401);
		}
		if (choice == 2)
			end();
	}
break;

beginstate 22;
	if ((get_flag(200,5) == 1) && (character_in_party(401) > 0)) {
		reset_dialog_preset_options(0);
		add_dialog_str(0,"Monson turns to you. _Well, I'm gonna hurry on ahead and let the others know it's time to leave. Thanks for your help._",0);
		add_dialog_str(1,"Without another word, he hurries away.",0);
		choice = run_dialog(0);
		if (choice == 1)
			remove_char_from_party(401);
	}
break;